package com.czk.rdd.operator.action

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Author:ChenZhangKun
 * @Date: 2021/12/10 14:25
 */
object CountByKey {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("spark://180.76.242.86:7077").setAppName("RDD")
    val sc = new SparkContext(sparkConf)
    val rdd = sc.makeRDD(List(1,2,3,4))

    // 统计出现的次数
    val intToLong: collection.Map[Int, Long] = rdd.countByValue()
    println(intToLong)
    //

    val rdd1 = sc.makeRDD(List(("a",1),("b",2)))
    val stringToLong: collection.Map[String, Long] = rdd1.countByKey()

    println(stringToLong)
  }


}
